<template>
  <div class="login-bg">
    <div class="login-banner">
      <div class="login-left">
        <div class="title">
          管理系统
        </div>
      </div>
      <div class="login-right">
        <div class="login-content">
          <div class="header">欢迎登录</div>
          <div class="item">
            <div class="input">
              <img src="../../assets/images/user.png" alt="">
              <label>
                <input type="text" v-model="auth.loginName">
              </label>
            </div>
          </div>
          <div class="item">
            <div class="input">
              <img src="../../assets/images/lock.png" alt="">
              <label>
                <input type="password" v-model="auth.password" @keypress.enter="login">
              </label>
            </div>
          </div>
          <div class="item">
            <button @click="login">登 录</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Login",
  data() {
    return {
      auth: {
        loginName: "",
        password: ""
      }
    };
  },
  created() {
  },
  methods: {
    login() {
      this.$http.post("/cauth/sys/auth/login", this.auth, res => {
        let data = res.data || {};
        if (data.token) {
          if (data.hasOwnProperty("roles")) {
            if (data.roles && data.roles.includes("SUPER_ADMIN")) {
              localStorage.setItem(this.$config.authInfo, JSON.stringify(data));
              this.$router.push({
                name: 'org'
              });
              return;
            }
          }
        }
        this.$message.warning("无访问权限！");
      }, false, true, true);
    }
  }
};
</script>

<style lang="scss" scoped>
.login-bg {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image: url("../../assets/images/login-bg.png");
  background-size: 100% 100%;

  .login-banner {
    width: 100vw;
    height: 350px;
    background-color: rgba(#041E25, 0.5);
    display: flex;
    flex-direction: row;

    .login-left {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;

      .title {
        font-size: 60px;
        width: 60%;
        color: white;
        font-family: "PingFang SC Semibold", "仿宋", serif;
      }
    }

    .login-right {
      flex: 1;

      .login-content {
        width: 350px;
        height: 100%;

        .header {
          color: white;
          padding: 20px 10px;
          font-size: 28px;
          font-family: "PingFang SC Regular", "仿宋", serif;
          text-align: left;
        }

        .item {
          padding: 15px 10px;

          button {
            width: 100%;
            background-color: #0896BA;
            border: 0;
            height: 40px;
            color: white;
            font-size: 16px;
            font-family: "PingFang SC Regular", "仿宋", serif;
            cursor: pointer;
          }

          .input {
            height: 35px;
            border-bottom: 1px solid #979797;
            position: relative;

            img {
              position: absolute;
              right: 8px;
              top: 8px;
            }

            input {
              width: 100%;
              background-color: transparent;
              height: 100%;
              color: white;
              border: 0;
              padding-left: 10px;
            }
          }
        }
      }
    }
  }
}
</style>